/**
 * @file Backend.cpp
 * @author ...
 * @brief 
 * @version 1.0
 * @date 2025-10-10
 * 
 * @copyright Copyright (c) 2025
 * 
 */

#include "Backend.hpp"

#include <QAbstractSocket>
#include <QPainter>
#include <QSettings>
#include <QTcpSocket>
#include <QtEndian>

#define MAX_VELOCITY 180

Backend::Backend(QObject *parent) : QObject(parent) {
    // 每秒更新数据
    connect(&m_timer, &QTimer::timeout, this, [this]() {
        // 触发时间更新信号
        emit timerUpdate();
        // 速度每秒增加1，超过最大值则重置为0
        m_velocity = (m_velocity + 1) % (MAX_VELOCITY + 1);
        emit statusUpdate();
        // 创建两张黑色图片，中间分别打印红色、白色当前时间戳
        QImage camera1Image(640, 480, QImage::Format_RGB32);
        camera1Image.fill(Qt::black);
        QPainter painter1(&camera1Image);
        painter1.setPen(Qt::red);
        painter1.drawText(camera1Image.rect(), Qt::AlignCenter, dateTime());
        painter1.end();
        pushCamera1Frame(camera1Image);

        QImage camera2Image(640, 480, QImage::Format_RGB32);
        camera2Image.fill(Qt::black);
        QPainter painter2(&camera2Image);
        painter2.setPen(Qt::white);
        painter2.drawText(camera2Image.rect(), Qt::AlignCenter, dateTime());
        painter2.end();
        pushCamera2Frame(camera2Image);
    });
    m_timer.start(1000);
}

Backend::~Backend() {}
